package com.sample.paxos;

import java.util.concurrent.TimeUnit;

import com.sample.paxos.sm.SampleStateMachine;
import com.swak.exception.RemotingException;
import com.swak.paxos.Node;
import com.swak.paxos.Paxos;
import com.swak.paxos.PaxosConfig;
import com.swak.paxos.PaxosConfig.GroupConfig;
import com.swak.utils.Lists;

/**
 * PaxosNodeA.
 * 
 * @author 618lf
 */
public class PaxosNodeA {

	public static void main(String[] args) throws RemotingException, InterruptedException {
		PaxosConfig config = new PaxosConfig();
		config.setTimeUnit(TimeUnit.SECONDS);
		config.setPaxosLogStoragePath("./paxos-storage/nodeA");
		config.getCluster().setName("Paxos").setPeerID("NodeA");
		config.getSmFac().addGlobalSM(new SampleStateMachine());

		// 设置分组, 设置分组的同步集合
		GroupConfig group = new GroupConfig();
		group.getNodes().addAll(Lists.newArrayList("NodeA", "NodeB"));
		config.getGroups().add(group);

		Node node = Paxos.runPaxos(config);
		Thread.sleep(10000);
		node.propose(0, "HelloA...", 1);
	}
}
